<template>
  <section>
    webWorkerDemo
    <el-button @click="test">测试</el-button>
    <div>{{text}}</div>
  </section>
</template>

<script>
import Worker from '../utils/test.worker';
let worker = new Worker()
let text = 'trtrtr'
export default {
  name:'WebWorkerDemo',
  data () {
    return {
      text
    }
  },
  methods:{
    test() {
      worker.postMessage('來自主綫程的問候');
      worker.onmessage = function(event) {
        //主线程接收到工作线程的消息
        console.log('主綫程收到的消息：',event)
        
        //关闭线程
        worker.terminate();
      }
    }
  }
}
</script>

<style>

</style>